package com.xiaoye.qbproject.controller.qbzt;


import com.xiaoye.qbproject.controller.base.BaseController;
import com.xiaoye.qbproject.domain.AjaxResult;
import com.xiaoye.qbproject.domain.QbSubject;
import com.xiaoye.qbproject.page.TableDataInfo;
import com.xiaoye.qbproject.service.QbSubjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.List;

/**
 * 情报专题
 */
@RestController
@RequestMapping("/subject")
public class QbSubjectController extends BaseController {

    @Autowired
    QbSubjectService qbSubjectService;

    @GetMapping("/list")
    public TableDataInfo list(QbSubject qbSubject, HttpServletRequest request) {
        startPage();
        List<QbSubject> list = qbSubjectService.getSubjectListAndSub(qbSubject, request);
        return getDataTable(list);
    }

    /**
     * @param qbSubject
     * @param request
     * @description: 获取我的订阅专题列表
     * @author: ChenYao
     * @return: com.xiaoye.qbproject.page.TableDataInfo
     * @ceateDate: 2025/1/15 下午5:06
     */

    @GetMapping("/getMySubscriptionSubjectList")
    public TableDataInfo getMySubscriptionSubjectList(QbSubject qbSubject, HttpServletRequest request) {
        startPage();
        List<QbSubject> list = qbSubjectService.getMySubscriptionSubjectList(qbSubject, request);
        return getDataTable(list);
    }

    @GetMapping("/{id}")
    public AjaxResult get(@PathVariable String id) {
        return AjaxResult.success(qbSubjectService.getById(id));
    }

    @PostMapping
    public AjaxResult add(@RequestBody QbSubject qbSubject) {
        return toAjax(qbSubjectService.save(qbSubject));
    }

    @PutMapping
    public AjaxResult edit(@RequestBody QbSubject qbSubject) {
        return toAjax(qbSubjectService.editSubject(qbSubject));
    }

    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        if (ids == null || ids.length == 0) {
            return AjaxResult.error("请选择要删除的数据");
        }
        qbSubjectService.delSubject(Arrays.asList(ids));
        return AjaxResult.success();
    }


}
